package com.security.dao.service;

import com.security.dao.iservice.IUserService;
import com.security.dao.model.User;
import com.security.dao.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserService implements IUserService, UserDetailsService {
    @Autowired
    private UserRepository userRepository;
    @Override
    public   User findByPhoneAndPassword(String phone, String password){
       return userRepository.findByPhoneAndPassword(phone,password);
    }
    @Override
    public   User findByUserName(String userName){
        return userRepository.findByUserName(userName);
    }
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return userRepository.findByUserName(username);
    }
}
